package org.linloong.modules.apis.monitor.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.linloong.modules.apis.monitor.dto.RealTimeAggDTO;
import org.linloong.modules.apis.monitor.dto.MultiSensorWithUnitAggDTO;
import org.linloong.modules.apis.monitor.service.RealTimeAggregationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/agg")
@RequiredArgsConstructor
@Tag(name = "实时聚合查询接口", description = "动态计算设备分组的年月平均值，无定时任务")
public class RealTimeAggController {

    private final RealTimeAggregationService aggregationService;

    /**
     * 实时查询指定设备分组的年月平均值
     */
    @Operation(summary = "实时查询设备分组的聚合数据", description = "动态计算该分组所有指标的年度和月度平均值")
    @GetMapping("/group/{groupId}")
    public RealTimeAggDTO getGroupAggregation(
            @Parameter(description = "设备分组ID", required = true, example = "123e4567-e89b-12d3-a456-426614174000")
            @PathVariable String groupId) {
        return aggregationService.calculateGroupAggregation(groupId);
    }

    /**
     * 查询指定设备分组的多传感器月度数据（带单位）
     */
    @Operation(summary = "查询多传感器月度数据", description = "返回[{year: 2025, data: [{month: '10', sensor: [{name: '温度', value: '8', unit: '°C'}, ...]}, ...]}, ...]")
    @GetMapping("/month/{groupId}")
    public List<MultiSensorWithUnitAggDTO> getMultiSensorMonthData(
            @Parameter(description = "设备分组ID", required = true, example = "123e4567-e89b-12d3-a456-426614174000")
            @PathVariable String groupId) {
        return aggregationService.queryMultiSensorMonthData(groupId);
    }
}